import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    appid: "wxc27248e7a5edbae6",
    userInfo: {},
    userCode: "10001",
    programName: "经开区教育事务局",
    jkq: {
      name: "昆明经济技术开发区教育局",
      eng:
        "Education Bureau of Kunming Economic and Technological Development Zone"
    }
  },
  mutations: {
    // 重新赋值
    removeState(state) {
      if (localStorage.getItem("userInfo")) {
        state.userInfo = JSON.parse(localStorage.getItem("userInfo"));
        localStorage.removeItem("userInfo");
      }
    },
    // 保存state 用户敏感信息
    saveState(state) {
      localStorage.setItem("userInfo", JSON.stringify(state.userInfo));
    },
    set_userInfo(state, msg) {
      state.userInfo = {
        ...msg
      };
      state.userCode = msg.zh_id;
    },
    // 退出登录
    logOut(state) {
      state.userInfo = {};
      window.location.reload();
    }
  },
  actions: {},
  modules: {}
});
